import React from 'react';

import {
    ConfirmOpt
} from './types';

import show from './show';

import Modal from './modal';

import * as Const from '../../const';

export default (opt: ConfirmOpt) => (
    new Promise((resolve, reject) => {
        const {
            title,
            message,
            cancelText,
            confirmText,
            showClose = true
        } = opt || {};

        const cancelButton = {
            onPress: reject,
            textStyle: {color: `#898989`},
            text: cancelText || `Cancel`
        }

        const confirmButton = {
            onPress: resolve,
            textStyle: {color: Const.color},
            text: confirmText || `Confirm`
        }

        const props = {
            title: title,
            message: message,
            showClose:showClose,
            buttons: [cancelButton, confirmButton]
        }

        show(<Modal {...props}/>)
    })
)